package main

import (
	"context"
	"log"
	"time"

	hello "eg1/proto"

	"github.com/micro/go-micro"
	"github.com/micro/go-micro/service/grpc"
)

type Say struct{}

func (s *Say) Hello(ctx context.Context, req *hello.Request, rsp *hello.Reponse) error {

	log.Print("Received Say.Hello request")
	rsp.Msg = "hello" + req.Name
	return nil
}

func main() {
	service := grpc.NewService(
		micro.Name("go.micro.srv.greeter"),     // 服务名称注册
		micro.RegisterTTL(time.Second*30),      // 过期时间
		micro.RegisterInterval(time.Second*10), // 容错
	)

	// optionally setup command line usage
	service.Init() // 服务初始化
	// register handlers
	hello.RegisterSayHandler(service.Server(), new(Say))
	//run server
	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}
